home *** CD-ROM | disk | FTP | other *** search
Wrap
#! /bin/sh # hplip initscript for the HP Linux Printing and Imaging System # Copyright (c) 2004-2006 by Henrique de Moraes Holschuh <hmh@debian.org> # Distributed under the GPLv2 or newer # # $Id: hplip.init,v 1.16 2006/10/26 15:39:43 hmh Exp $ PATH=/sbin:/bin:/usr/sbin:/usr/bin DESC="HP Linux Printing and Imaging System" # For manual setuid/gid SUID_USER=hplip SGID_GROUP=lp DAEMON1=/usr/sbin/hpiod NAME1=hpiod PROCNAME1=$NAME1 PIDFILE1=/var/run/hplip/hpiod.pid DAEMON2=/usr/sbin/hpssd NAME2=hpssd PROCNAME2=python PIDFILE2=/var/run/hplip/hpssd.pid FILES2="/var/run/hplip/hpssd.pid /var/run/hplip/hpssd.port" HPIODOPTIONS= HPSSDOPTIONS= RUN_HPIOD_AS_ROOT=yes [ -r /etc/default/hplip ] && . /etc/default/hplip case "$RUN_HPLIP" in [nN]*) exit 0 esac test -x ${DAEMON1} || exit 0 . /lib/lsb/init-functions set -e ### ### dpkg-statoverride support ### createdir() { # $1 = user # $2 = group # $3 = permissions (octal) # $4 = path to directory [ -d "$4" ] || mkdir -p -m "$3" "$4" chown -R -H --preserve-root "$1:$2" "$4" chmod "$3" "$4" } fixdirs() { dir=$(dpkg-statoverride --list /var/run/hplip) || { echo "You are missing a dpkg-statoverride on /var/run/hplip. Fix it, otherwise you risk silent breakage on upgrades. If you have no idea what to do, just reinstall hplip and it will fix itself." >&2 exit 1 } [ -z "$dir" ] || createdir $dir # clear exit status : } ### DIDSOMETHING=0 reload_cups() { if [ ${DIDSOMETHING} -ne 0 ] ; then # Tell cupsys that we (may) have a new ative backend # be silent about it to avoid unneeded hassles duing # shutdowns -- it is not like we care if this suceeds or # not... invoke-rc.d --quiet cupsys reload >/dev/null 2>&1 || true fi return 0 } start_daemon() { DAEMON="$1" PIDFILE="$2" NAME="$3" PROCNAME="$4" SSDOPT="$5" DAEMONOPT="$6" START="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME} ${SSDOPT}" [ -n "${DAEMONOPT}" ] && START="${START} -- ${DAEMONOPT}" if start-stop-daemon ${START} >/dev/null 2>&1 ; then #success DIDSOMETHING=1 else if start-stop-daemon --test ${START} >/dev/null 2>&1; then #failed return 1 else #already running return 0 fi fi return 0 } stop_daemon() { DAEMON="$1" PIDFILE="$2" NAME="$3" PROCNAME="$4" # yes, it is --start. go read the manpage STOP="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME}" if start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \ --retry 10 --name ${PROCNAME} \ >/dev/null 2>&1 ; then # success DIDSOMETHING=1 # FIXME: change hpiod so that this is not necessary sleep 2 else if start-stop-daemon --test ${STOP} >/dev/null 2>&1; then # already stopped return 0 else # failed, still running return 1 fi fi return 0 } do_start () { log_daemon_msg "Starting ${DESC}" fixdirs case "$RUN_HPIOD_AS_ROOT" in [nN]*) HPIOD_SSDOPT="--chuid ${SUID_USER} --group ${SGID_GROUP}";; *) HPIOD_SSDOPT="" esac log_progress_msg "${NAME1}" if start_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \ "${PROCNAME1}" "${HPIOD_SSDOPT}" \ "${HPIODOPTIONS}" && \ { log_progress_msg "${NAME2}" for i in ${FILES2} ; do [ -f "$i" ] && chown "${SUID_USER}:${SGID_GROUP}" "$i" : done start_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \ "${PROCNAME2}" "--chuid ${SUID_USER} --group ${SGID_GROUP}" \ "${HPSSDOPTIONS}" } ; then log_end_msg 0 reload_cups else log_end_msg 1 || true return 1 fi return 0 } do_stop () { log_daemon_msg "Stopping ${DESC}" log_progress_msg "${NAME1}" if stop_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \ "${PROCNAME2}" then log_progress_msg "${NAME2}" stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \ "${PROCNAME1}" && { log_end_msg 0 return 0 } log_end_msg 1 || true return 1 else log_end_msg 1 || true log_daemon_msg "Stopping ${DESC}" log_progress_msg "${NAME2}" if stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \ "${PROCNAME1}" ; then log_end_msg 1 || true else log_end_msg 0 fi log_failure_msg "Failed to stop all components of ${DESC}." return 1 fi } case "$1" in start) set -e do_start exit 0 ;; stop) set -e do_stop exit 0 ;; restart|force-reload) do_stop || true set -e do_start exit 0 ;; *) log_warning_msg "Usage: $0 {start|stop|restart|force-reload}" exit 1 ;; esac exit 0